package com.sky.controller.admin;

import com.sky.dto.OrdersCancelDTO;
import com.sky.dto.OrdersConfirmDTO;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.dto.OrdersRejectionDTO;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.OrderService;
import com.sky.vo.OrderOverViewVO;
import com.sky.vo.OrderStatisticsVO;
import com.sky.vo.OrderVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController("adminOrderController")
@RequestMapping("/admin/order")
@Slf4j
@Api(tags = "商家订单接口")
public class OrderController {
    @Autowired
    private OrderService orderService;
    @GetMapping("/statistics")
    @ApiOperation("商家查看各个订单数量")
    public Result<OrderStatisticsVO> variousCount(){
        OrderStatisticsVO orderStatisticsVO = orderService.getvariousCount();
        return Result.success(orderStatisticsVO);
    }
    @GetMapping("/conditionSearch")
    @ApiOperation("商家查询订单")
    public Result<PageResult> listOrder(OrdersPageQueryDTO ordersPageQueryDTO){
        PageResult pageResult = orderService.listOrders(ordersPageQueryDTO);
        return Result.success(pageResult);

    }
    @GetMapping("/details/{id}")
    @ApiOperation("商家查询订单详情")
    public Result<OrderVO> getOrderDetailById(@PathVariable Long id){
        OrderVO orderDetailById = orderService.getOrderDetailById(id);
        return Result.success(orderDetailById);
    }
    @PutMapping("/cancel")
    @ApiOperation("商家取消订单")
    public Result cancel(@RequestBody OrdersCancelDTO ordersCancelDTO){
        orderService.cancel(ordersCancelDTO);
        return Result.success();
    }

    @PutMapping("/confirm")
    @ApiOperation("商家接单")
    public Result getOrdered(@RequestBody OrdersConfirmDTO ordersConfirmDTO){
        orderService.confirm(ordersConfirmDTO);
        return Result.success();
    }
    @PutMapping("/rejection")
    @ApiOperation("商家拒单")
    public Result reject(@RequestBody OrdersRejectionDTO ordersRejectionDTO){
        orderService.reject(ordersRejectionDTO);
        return Result.success();
    }
    @PutMapping("/delivery/{id}")
    @ApiOperation("商家开始派单")
    public Result delivery(@PathVariable Long id){
            orderService.delivery(id);
            return Result.success();
    }
    @PutMapping("/complete/{id}")
    @ApiOperation("商家完成订单")
    public Result complete(@PathVariable Long id){
        orderService.complete(id);
        return Result.success();
    }



}
